<%@ page language="java" pageEncoding="UTF-8" import="ll.sms.util.*"%>
<html>
  <head>
    <title>代理注册</title>
	<link rel="stylesheet" type="text/css" href="../ext/ext-all.css" />
	<link rel="stylesheet" type="text/css" href="../myjs/multiselect.css" />
    <link rel="stylesheet" type="text/css" href="../ext/statusbar.css" />
	<script type="text/javascript" src="../ext/ext-base.js"></script>
	<script type="text/javascript" src="../ext/ext-all.js"></script>
    <script type="text/javascript" src="../myjs/DDView.js"></script>
    <script type="text/javascript" src="../myjs/MultiSelect.js"></script>
    <script type="text/javascript" src="../myjs/ItemSelector.js"></script>
    <script type="text/javascript" src="../ext/ValidationStatus.js"> </script>

<style type="text/css">
.settings {
	background: url(../images/cmp.gif) left top no-repeat !important;
	}

.popup {
    position: absolute;
    z-index: 50;
    border-collapse: collapse;
}

.popup td.corner {height: 15px;    width: 19px;}
.popup td#topleft { background-image: url(../images/bubble-1.png); }
.popup td.top { background-image: url(../images/bubble-2.png); }
.popup td#topright { background-image: url(../images/bubble-3.png); }
.popup td.left { background-image: url(../images/bubble-4.png); }
.popup td.right { background-image: url(../images/bubble-5.png); }
.popup td#bottomleft { background-image: url(../images/bubble-6.png); }
.popup td.bottom { background-image: url(../images/bubble-7.png); text-align: center;}
.popup td.bottom img { display: block; margin: 0 auto; }
.popup td#bottomright { background-image: url(../images/bubble-8.png); }

.popup table.popup-contents {
    font-size: 12px;
    line-height: 1.2em;
    background-color: #fff;
    color: #666;
    font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", sans-serif;
    }

table.popup-contents th {
    text-align: right;
    text-transform: lowercase;
    }

table.popup-contents td {
    text-align: left;
    }
</style>
<%
String notAuthoChannel = ExtJsonBuilder.getAllChannels();
%>

<script type="text/javascript">

function showPopup(element_id,username){

 username = "<img alt=\"\" src=\"../img/alert.gif\"/><font color=red>"+username+"</font>";
  var div = createElement("div");
  div.id = "popup";
var x = 0;
var y = 0;

  div.innerHTML='\
        <table style="top:' + y + 'px; left:' + x + 'px;" class="popup">\
          <tbody>\
            <tr>\
              <td class="corner" id="topleft"></td>\
              <td class="top"></td>\
              <td class="corner" id="topright"></td>\
            </tr>\
            <tr>\
              <td class="left"></td>\
              <td><table class="popup-contents">\
                <tbody>\
                    <tr>\
                      <td>'+username+'</td>\
                    </tr>\
                </tbody>\
              </table></td>\
              <td class="right"></td>\
            </tr>\
            <tr>\
              <td id="bottomleft" class="corner"></td>\
              <td class="bottom"><!--<img src="../images/bubble-tail2.png" alt="popup tail" height="29" width="30">--></td>\
              <td class="corner" id="bottomright"></td>\
            </tr>\
          </tbody>\
        </table>';
  document.body.appendChild(div);
  //Element.show("popup");
}

function hidePopup(){
   document.getElementById('popup').parentNode.removeChild(document.getElementById('popup'));
}

function createElement(element) {
    if (typeof document.createElementNS != 'undefined') {
        return document.createElementNS('http://www.w3.org/1999/xhtml', element);
    }
    if (typeof document.createElement != 'undefined') {
        return document.createElement(element);
    }
    return false;
}
</script>

	<script type="text/javascript">
	window.onload =(function(){
	Ext.BLANK_IMAGE_URL = '../images/s.gif';


		//Ext.QuickTips.init();
		var wi = 600;
		var w;


		    var smsname = new Ext.form.TextField({ //text
                 id: 'auname',
                 fieldLabel: '代理用户名',
                 name: 'auname',
 				 defaultType: 'textfield',
                 grow: false,
                 regex : /^[a-zA-Z0-9_\u4e00-\u9fa5]{2,32}$/,
                 allowBlank:false,
                 blankText :'代理用户名必须填写',
                 regexText : "用户名允许的字符为:英文字母、中文、下划线,长度为4-32位"
             });


             smsname.on('blur', function(e){
				  if(name==''){
				  	return
				  }
                  var name = this.getValue();
				  Ext.Ajax.request({
                  url : '../ajaxjsp/system.jsp',
                  method : 'POST',
                  params : {
                  		name : name,
                  		flag : 'usernamecheck',
                  		type : 'a'
                  },
                  success: function(response, options) {
                        //获取响应的json字符串
                       var responseArray = Ext.util.JSON.decode(response.responseText);
                            if(responseArray.success==true){
								try{hidePopup();}catch(e){}
                            }
                            else{
								showPopup('auname','['+Ext.getCmp('auname').getValue()+"]该用户名已经被使用!");
                            }
                         }
              });
             });



		function getmaodieview(){
		var isForm;
		var nwindow;
	try{
		isForm = new Ext.form.FormPanel({
        //title: 'ItemSelector Test',
        //width:700,
        //regin
        bodyStyle: 'padding:10px;',
        //renderTo: 'itemselector',
        items:[{
            xtype:"itemselector",
            name:"itemselector",
            fieldLabel:"为该代理配置通道",
            dataFields:["code", "desc"],
            toData:[],
            msWidth:250,
            msHeight:200,
            valueField:"code",
            displayField:"desc",
            imagePath:"../images/",
            toLegend:"已配置通道",
            fromLegend:"未配置通道",
            fromData:<%=notAuthoChannel%>,
            toTBar:[{
                text:"重置",
                handler:function(){
                    var i=isForm.getForm().findField("itemselector");
                    i.reset.call(i);
                }
            }]
        }],

        buttons: [{
            text: '确定',
            handler: function(){
                if(isForm.getForm().isValid()){
                   doset(isForm.getForm().getValues(true));
                }
            }
        }]
    });
	nwindow =  new Ext.Window({
	    title    : '通道配置',
		width    : 800,
		height   : 400,
		layout   : 'fit',
		//applyTo : 'panel123',
		closeAction :'hide',
		items    : [
			isForm
		]
	});
	}catch(e){}
	return nwindow;

	}

	var showproxy =new Ext.Button({
	        // applyTo:'login-button-group',
	         text: '配置通道',
			 iconCls:'settings',
	         handler: function()
		         {

					if(w){
					w.show();
					}else{
					try{
					w = getmaodieview();
					w.show();
					}catch(e){}
					}
		         }
		     	});

//****************************************************************
//****************************************************************
//****************************************************************

	    var simple = new Ext.FormPanel({
	    id : 'simpleform',
        //labelWidth: 100, // label settings here cascade unless overridden
        url:'../ajaxjsp/proxyregdit.jsp',
        frame:true,
        //title: '代理注册',
        bodyStyle:'padding:5px 5px 0',
        width: '80%',
        renderTo:'myf',
        autoHeight: true,
        defaults: {width: 230},
        defaultType: 'textfield',
        labelAlign: 'right',
        waitMsgTarget: true,

        items: [
           smsname,
           {
                fieldLabel: '密码',
                name: 'apwd',
                vtype:'alphanum',
                vtypeText:'密码只能包括字母或者数字',
                allowBlank:false,
                id:'apwd',
                blankText :'密码必须填写'
            },{
                fieldLabel: '重新输入密码',
                name: 'reapwd',
                vtype:'alphanum',
                vtypeText:'密码只能包括字母或者数字',
                allowBlank:false,
                blankText :'重复密码必须填写'

            },{
                fieldLabel: '代理公司名',
                name: 'acompany',
                allowBlank:false,
                blankText :'代理公司名必须填写'
            },{
                fieldLabel: '公司地址',
                name: 'aaddress'
            },{
                fieldLabel: '公司电话',
                name: 'aphone'
            },{
                fieldLabel: '联系人',
                name: 'alinkman',
                allowBlank:false,
                blankText :'联系人必须填写'
            },{
                fieldLabel: '联系人电话',
                name: 'alinkmanphone',
                allowBlank:false,
                blankText :'联系人电话必须填写'
            },{
                fieldLabel: '联系人QQ',
                 xtype:'numberfield',
                name: 'alinkmanqq'
            },
            {
                fieldLabel: '可发短信数',
                name: 'asmsnum',
                xtype:'numberfield',
                allowBlank:false,
                blankText :'可发短信数必须填写'
            },{
                fieldLabel: '是否可用',
                name: 'aavailable',
                xtype:'hidden'
            },{
                fieldLabel: '已配置代理',
                name: 'adefaultchannel',
                id : 'adefaultchannel',
                xtype:'hidden'
            }
            ,showproxy
            ]
            ,
        buttons: [{
            text: '注册',
            handler : function(){

			if(!simple.getForm().isValid()){
			alert('信息填写错误，请点击查看低栏信息提示！');
			return;
			}
           	var v = simple.getForm().findField('adefaultchannel').getValue();
			if(Ext.isEmpty(v)){

			alert("你没有对代理配置通道!");
			}else{
			dosubmit();
			}

			function dosetchannel(btn){
				if(btn=='yes'){
					dosubmit();
				}else{
					if(w){
					w.show();
					}else{
					w = getmaodieview();
					w.show();
					}
				}
			}

			function dosubmit(){

			 simple.form.submit({

					waitMsg : '正在处理......',
					success : function(form, action) {
            	        alert(action.result.msg);
						window.location.reload();
					},
					failure : function(form, action) {
						if (action.failureType == Ext.form.Action.SERVER_INVALID){
							alert(action.result.errors.msg);
							return;
							}else{
							alert('--------非法输入-------');
							}
					}
				});
			}

            }
        },{
            text: '重填',
            handler : function(){
          		simple.form.reset();
            }
        }]

    });


  new Ext.Panel({
        title: '代理注册',
        renderTo:'myf',
        width: '80%',
        height : '70%',
        layout: 'fit',
        items: simple,
        bbar: new Ext.StatusBar({
            id: 'form-statusbar',
            defaultText: '&nbsp;&nbsp;就绪',
            plugins: new Ext.ux.ValidationStatus({form:'simpleform',showText : '警告:输入的信息存在错误(点击这里获得详细描述...)',hideText : '点击隐藏提示信息'})
        })
    });

	function doset(value){
	simple.getForm().findField('adefaultchannel').setValue(value);
	w.hide();
	}
    });

	</script>

  </head>

  <body bgcolor="#ffffff">
 <br>
      <div id="panel123"></div>
     <div id="myf" align="center"></div>
    <input id="sel" type="hidden"/>

  </body>
</html>

